
(function () {
    'use strict';

    angular.module('KingAdmin.pages.pdev.camera')
        .controller('FirmwareCtrl', FirmwareCtrl);

    /** @ngInject */
    function FirmwareCtrl($scope, $stateParams, $state,$uibModalInstance, FirmwareService, DictService, DeviceService) {
        var kt = this;
        kt.firmware = {};
        kt.title = '编辑设备固件';

        if($stateParams.id){
            if ($stateParams.isView) {
                kt.isView = true;
                kt.title = '查看设备固件';
            }

            FirmwareService.getInfo({id:$stateParams.id},
                function (data) {
                kt.firmware = data;
            })
        }else{
            kt.isAdd = true;
            kt.title = '添加设备固件';
            kt.firmware = {

            };
        }

        kt.devList = [];
        DeviceService.getDictList(function (data) {
            kt.devList = data.result;
            kt.isShowDev = true;
        });

        kt.devstatus = [];
        DictService.getList('DEVICESTATUS',function (data) {
            kt.devstatus = data.result;
            kt.isShowStatus = true;
            // $scope.$digest();
        });

        kt.save = function () {
            var form = new FormData(angular.element("#firmware-form"));
            console.log(form);

            FirmwareService.save(kt.firmware,function (data) {
                $uibModalInstance.close(true);
            });
        };

        $uibModalInstance.rendered.then(function() {

        });
    }

})();
